Page({
    data:{
      keywords:'',
      historykeywords:[],//历史搜索记录
    },
    onShow(){
        let historykeywords = wx.getStorageSync('historykeywords') || []
        this.setData({
          historykeywords
        })
    },
    _keywordsInput(e){
      // console.log()
      let keywords = e.detail.value 
      console.log(keywords,'aaaaa')
      this.data.keywords = keywords
    },
    _goToSearchList(){
      let keywords = this.data.keywords
      if( keywords == '' ){
        wx.showToast({
          title: '请输入关键字',
          icon:'none'
        })
        return
      }
  
      //设置用户最近搜索的缓存 historykeywords
        let historykeywords = wx.getStorageSync('historykeywords') || []
  
        let index = historykeywords.findIndex(item=>{
            return item == keywords
        })
       
        console.log(index)
        if( index != -1 ){
          historykeywords.splice(index,1)
        }
        historykeywords.unshift( keywords )
        wx.setStorageSync('historykeywords', historykeywords)
      //设置用户最近搜索的缓存
      wx.navigateTo({
        url: `/pages/searchlist/searchlist?keywords=${keywords}`,
      })
    }
  })